﻿using OA.Models.Enums;
using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace OA.Models
{
    /// <summary>
    ///  账号
    ///  账号直接绑定员工
    /// </summary>
    public class Account
    {
        [Key]
        [Required]
        [DisplayName("工号")]
        [DatabaseGenerated(DatabaseGeneratedOption.None)]
        public string Id { get; set; }

        #region 账户属性

        /// <summary>
        ///  密码
        ///  经过MD5加密后存入数据库
        ///  最小长度为6
        /// </summary>
        [Required]
        [DisplayName("密码")]
        [DataType(DataType.Password)]
        [StringLength(160, MinimumLength = 5)]
        public string Password { get; set; }

        [Required]
        [DisplayName("创建日期")]
        [DataType(DataType.DateTime)]
        public DateTime Createdate { get; set; }
        
        /// <summary>
        ///  账户状态
        ///  0: 申请中
        ///  1: 可用
        ///  2: 不可用
        /// </summary>
        [DisplayName("账户状态")]
        [DefaultValue(0)]
        public AccountState AccountState { get; set; }

        /// <summary>
        ///  头像
        ///  存储图片路径
        ///  默认头像: //
        /// </summary>
        [DisplayName("头像")]
        [DefaultValue("")]
        public string Photo { get; set; }

        #endregion

        #region 员工属性

        /// <summary>
        ///  姓名
        /// </summary>
        [Required]
        [DisplayName("姓名")]
        public string Name { get; set; }

        /// <summary>
        ///  性别
        ///  0: 保密
        ///  1: 男
        ///  2: 女
        /// </summary>
        [DefaultValue(0)]
        [DisplayName("性别")]
        public Gender Gender { get; set; }

        /// <summary>
        ///  生日
        /// </summary>
        [DisplayName("生日")]
        [DataType(DataType.Date)]
        [DisplayFormat(DataFormatString = "{0:yyyy年MM月dd日}")]
        public DateTime? Birthday { get; set; }

        /// <summary>
        ///  邮箱
        /// </summary>
        [EmailAddress]
        [DisplayName("邮箱")]
        [DataType(DataType.EmailAddress)]
        [RegularExpression(@"^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+", ErrorMessage = "邮箱格式不正确")]
        public string Email { get; set; }

        /// <summary>
        ///  手机
        /// </summary>
        [Phone]
        [DisplayName("手机")]
        [DataType(DataType.PhoneNumber)]
        [RegularExpression(@"^1[3458][0-9]{9}$", ErrorMessage = "手机号格式不正确")]
        public string Phone { get; set; }

        /// <summary>
        ///  员工状态
        ///  0: 在职
        ///  1: 离职
        ///  2: 请假
        /// </summary>
        [Range(0, 2)]
        [DefaultValue(0)]
        [DisplayName("员工状态")]
        public EmployeeState State { get; set; }

        /// <summary>
        ///  在职岗位
        /// </summary>
        [Required]
        [DisplayName("岗位")]
        public int PostId { get; set; }
        [ForeignKey("PostId")]
        public virtual Post Post { get; set; }

        /// <summary>
        ///  所属部门
        /// </summary>
        [Required]
        [DisplayName("部门")]
        public int DepartmentId { get; set; }
        [ForeignKey("DepartmentId")]
        public virtual Department Department { get; set; }

        #endregion 
    }
}
